# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgname=pandoc-cli
pkgver=0.1.1.1
pkgrel=10
pkgdesc="Conversion between documentation formats"
url="https://pandoc.org"
license=("GPL")
arch=('loong64' 'x86_64')
provides=('pandoc')
conflicts=('pandoc')
replaces=('pandoc')
depends=('ghc-libs' 'hslua-cli' 'haskell-pandoc' 'haskell-pandoc-lua-engine' 'haskell-pandoc-server'
         'haskell-safe' 'haskell-temporary' 'haskell-wai-extra' 'haskell-warp')
makedepends=('ghc' 'uusi')
source=("https://hackage.haskell.org/packages/archive/$pkgname/$pkgver/$pkgname-$pkgver.tar.gz")
sha256sums=('1f41974aaa827682db5507e3c339babddda2c21b10aa70af9b8cd1c9be7d1ba3')

prepare() {
  cd $pkgname-$pkgver
  gen-setup
}

build() {
  cd $pkgname-$pkgver

  runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
    --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --datasubdir=haskell-pandoc-cli --enable-tests \
    --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
    --ghc-option=-optl-Wl\,-z\,relro\,-z\,now \
    --ghc-option='-pie' \
    -flua -f-nightly -fserver

  runhaskell Setup build $MAKEFLAGS
}

check() {
  cd $pkgname-$pkgver
  runhaskell Setup test --show-details=direct
}

package() {
  cd $pkgname-$pkgver
  runhaskell Setup copy --destdir="$pkgdir"
  install -D -m644 COPYING.md -t "$pkgdir"/usr/share/licenses/$pkgname/
  rm -f "$pkgdir"/usr/share/doc/$pkgname/COPYING.md

  LD_LIBRARY_PATH="$PWD/dist/build" dist/build/pandoc/pandoc --bash-completion > pandoc-completion.bash
  install -Dm644 pandoc-completion.bash "$pkgdir"/usr/share/bash-completion/completions/pandoc
}
